package Framework;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

public class img_PinchZoom extends pnl_Scrollable implements MouseListener, MouseMotionListener{

	int ii_zoomPercent = 100;
	double ii_Sensitivity = 00000001;
	Rectangle irect_Original;
	
	Point ipos_RightMouse;
	Point ipos_LeftMouse;
	boolean ib_Zoom;
	
	public img_PinchZoom(Rectangle rectangle, Rectangle rectangle2) {
		super(rectangle, rectangle2, true);
		this.addMouseListener(this);
		this.addMouseMotionListener(this);	
		irect_Original = rectangle2;
	}
	
	public void zoomFrame(){
		Rectangle Bounds = i_InternalFrame.getBounds();
		Bounds.height = (irect_Original.height / 100) * ii_zoomPercent;
		Bounds.width = (irect_Original.width / 100) * ii_zoomPercent;
		Bounds.x = (Bounds.x / 100) * ii_zoomPercent;
		Bounds.y = (Bounds.y / 100) * ii_zoomPercent;
		
		
		i_InternalFrame.setBounds(Bounds);
		System.out.println("New Bounds:" + Bounds);
	}
	public void mouseClicked(MouseEvent arg0) {
		if (arg0.getModifiersEx() != -4){
			ipos_RightMouse = arg0.getPoint();
			ib_Zoom = true;
			System.out.println("Active");
		}
		System.out.println(arg0.getModifiersEx());
	}
	
	public void mouseReleased(MouseEvent arg0) {
		ib_Zoom = false;	
	}
	
	public void mouseDragged(MouseEvent arg0) {
		if (ib_Zoom){
			int Distance = 0;
			// Getting Distance
			Distance += arg0.getY() - ipos_RightMouse.y;
			Distance += arg0.getX() - ipos_RightMouse.x;
			System.out.println("Distance: " + Distance);
			ii_zoomPercent = ii_zoomPercent - (int) (Distance * ii_Sensitivity);
			if (ii_zoomPercent < 0) {
				ii_zoomPercent = 0;
			}
			zoomFrame();
		}
	}
	public void mouseMoved(MouseEvent arg0) {}
	public void mouseEntered(MouseEvent arg0) {}
	public void mouseExited(MouseEvent arg0) {}
	public void mousePressed(MouseEvent e) {}
}
